package mylab.starters.eventbus.support.disruptor;

import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;
import mylab.starters.eventbus.api.EventModel;

@Slf4j
public abstract class ExecutableEventListener extends BaseEventListener<EventModel<?>> {

    @org.springframework.context.event.EventListener
    @Subscribe
    @Override
    public void onMessage(EventModel<?> message) {
        log.info("收到消息：{}", message);

        if (topic().equals(message.getTopic())) {
            handle(message);
        }
    }

    @Override
    public void onEvent(EventModel<?> event, long sequence, boolean endOfBatch) throws Exception {
        onMessage(event);
    }

    /**
     * 具体消息处理方法
     *
     * @param message
     */
    protected abstract void handle(EventModel<?> message);

}
